package edu.suda.basic.acm;

import java.util.LinkedList;
import java.util.Queue;

public class Game
{
	public static void main(String[] args)
	{
		int target = 8;
		int capacityA=16;
		int capacityB=78;
		Queue<GameState> nodeBucket = new LinkedList<GameState>();
		GameState root = new GameState();
		GameState.setCapacityA(capacityA);
		GameState.setCapacityB(capacityB);
		root.setVolumnA(0);
		root.setVolumnB(0);
		root.setExtensible(true);
		root.setParentState(null);
		root.setResultingOperation("开始");
		GameState.updateKnownStates(root);
		String opSeqs = "";
		nodeBucket.offer(root);

		GameState gs, gs2;
		while (!nodeBucket.isEmpty())
		{
			gs = nodeBucket.poll();
			gs.grow();

			gs2 = gs.getChildState1();
			if (gs2 != null)
			{
				if (gs2.getVolumnA() == target || gs2.getVolumnB() == target)
				{
					opSeqs = (gs2.getOpSeq());
					break;
				}
				else if (gs2.isExtensible() == true)
				{
					nodeBucket.offer(gs2);
				}
			}

			gs2 = gs.getChildState2();
			if (gs2 != null)
			{
				if (gs2.getVolumnA() == target || gs2.getVolumnB() == target)
				{
					opSeqs = (gs2.getOpSeq());
					break;
				}
				else if (gs2.isExtensible() == true)
				{
					nodeBucket.offer(gs2);
				}
			}
			gs2 = gs.getChildState3();
			if (gs2 != null)
			{
				if (gs2.getVolumnA() == target || gs2.getVolumnB() == target)
				{
					opSeqs = (gs2.getOpSeq());
					break;
				}
				else if (gs2.isExtensible() == true)
				{
					nodeBucket.offer(gs2);
				}
			}
			gs2 = gs.getChildState4();
			if (gs2 != null)
			{
				if (gs2.getVolumnA() == target || gs2.getVolumnB() == target)
				{
					opSeqs = (gs2.getOpSeq());
					break;
				}
				else if (gs2.isExtensible() == true)
				{
					nodeBucket.offer(gs2);
				}
			}
			gs2 = gs.getChildState5();
			if (gs2 != null)
			{
				if (gs2.getVolumnA() == target || gs2.getVolumnB() == target)
				{
					opSeqs = (gs2.getOpSeq());
					break;
				}
				else if (gs2.isExtensible() == true)
				{
					nodeBucket.offer(gs2);
				}
			}
			gs2 = gs.getChildState6();
			if (gs2 != null)
			{
				if (gs2.getVolumnA() == target || gs2.getVolumnB() == target)
				{
					opSeqs = (gs2.getOpSeq());
					break;
				}
				else if (gs2.isExtensible() == true)
				{
					nodeBucket.offer(gs2);
				}
			}
		}
		System.out.println("A容量为"+capacityA+"，B容量为"+capacityB+"，目标为"+target);
		if (!opSeqs.equals(""))
		{
			String[] opSeq = opSeqs.split(";");
			for (String s : opSeq)
			{
				System.out.println(s);
			}
			System.out.println("结束");
		}
		else
		{
			System.out.println("无解");
		}
	}
}
